package com.wqtz.chechai.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.lvbaseadapter.LvBaseAdapter;
import com.wqtz.chechai.base.lvbaseadapter.ViewHolder;
import com.wqtz.chechai.bean.ApprovalInfoBean;
import com.wqtz.chechai.bean.MessageBean;
import com.wqtz.chechai.view.activities.ApprovalInfoActivity;
import com.wqtz.chechai.view.activities.ApprovalInfoDetailActivity;
import com.yinglan.swiperefresh.SwipeMenu;
import com.yinglan.swiperefresh.SwipeMenuListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/2/16
 */

public class ApprovalInfoAdapter extends LvBaseAdapter<ApprovalInfoBean> implements SwipeMenuListView.OnMenuItemClickListener {
    private List<ApprovalInfoBean> mDatas = new ArrayList<>();
    /**
     * 2种状态：审批通过 审批拒绝
     */
    private final int PASSED = 0;
    private final int REFUSEED = 1;
    private Context mContext;


    public ApprovalInfoAdapter(Context context, int resId) {
        super(resId);
        mContext = context;
    }

    @Override
    public void bindDatas(final List<ApprovalInfoBean> list, final int position, ViewHolder holder) {
        mDatas.clear();
        mDatas.addAll(list);
        ApprovalInfoBean approvalInfoBean = list.get(position);
        holder.setText(R.id.tv_approval_people,approvalInfoBean.getApprovalName());
        holder.setText(R.id.tv_time,approvalInfoBean.getApprovalTime());
        switch (approvalInfoBean.getApprovalStatus()) {
            /**
             * 2种状态：审批通过 审批拒绝
             */
            case PASSED:
                //审批内容
                holder.setText(R.id.approval_detail, "[广州本田 雅阁 EX2010款...]报价为8万元万元万元万元万元万元万元万元万元");
                break;
            case REFUSEED:
                //审批内容
                holder.setText(R.id.approval_detail, "[广州本田 雅阁 EX2010款...]报价不通过！原因：行驶证资料不齐全，需要进一步补充");
                break;
        }
    }


    @Override
    public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
        switch (index) {
            case 0:
                Toast.makeText(mContext,"delete",Toast.LENGTH_SHORT).show();
                mDatas.remove(position);
                clearData();
                addData(mDatas);
                break;
            case 1:
                Toast.makeText(mContext,"查看",Toast.LENGTH_SHORT).show();
                toApprovalInfoActivity(position);
                break;
        }
        return false;
    }

    //跳转到审批详情
    private void toApprovalInfoActivity(int position) {
        //
        Intent intent = new Intent(mContext, ApprovalInfoDetailActivity.class);
        ApprovalInfoBean approvalInfoBean = mDatas.get(position);
        intent.putExtra("type", approvalInfoBean.getApprovalStatus());
        mContext.startActivity(intent);
    }

}
